﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace UIT_CV_Management
{
    public partial class UserControlKhenThuong : UserControl
    {
        bool isEveryThingOK = false;
        bool isTenGiaiThuongOK = false;
        bool isCoQuanQuyetDinhOK = false;
        bool isHinhThuongKhenThuong = false;
        bool isNoiCapOK = false;

        //obj
        KhenThuong khenThuong;

        public UserControlKhenThuong()
        {
            InitializeComponent();

            //hide all check image
            this.hideAllErrorImage();

            // init language
            this.initLanguage();
        }

        private void hideAllErrorImage()
        {
            pictureBoxCoQuanQUyetDinh.Visible = false;
            pictureBoxHinhThucKhenThuong.Visible = false;
            pictureBoxNoiCap.Visible = false;
            pictureBoxTenGiaiThuong.Visible = false;
        }

        private void initLanguage()
        {
            lblTenGiaiThuong.Text = Language._("KHENTHUONG_FORM_TENGIAITHUONG_LBL");
            lblHinhThucKhenThuong.Text = Language._("KHENTHUONG_FORM_HINHTHUCKHENTHUONG_LBL");
            lblCoQuanQuyetDinh.Text = Language._("KHENTHUONG_FORM_COQUANQUYETDINH_LBL");
            lblNoiCap.Text = Language._("KHENTHUONG_FORM_NOICAP_LBL");
            lblNgayCap.Text = Language._("KHENTHUONG_FORM_NGAYCAP_LBL");    
        }

        private void txbTenGiaiThuong_Validating(object sender, CancelEventArgs e)
        {
            bool isHasError = false;

            if (txbTenGiaiThuong.Text.Trim() == "")
                isHasError = true;

            if (isHasError)
            {
                isTenGiaiThuongOK = false;
                
                // change NoiSinh's background color to Tomato
                // Add UserTip
                txbTenGiaiThuong.BackColor = Color.Tomato;
                utpTip.Value = Language._("KHENTHUONG_FORM_TIP_TENGIAITHUONG_NULL");
                utpTip.Visible = true;
                pictureBoxTenGiaiThuong.Visible = false;
            }
            else
            {
                isTenGiaiThuongOK = true;
                txbTenGiaiThuong.BackColor = Color.White;
                pictureBoxTenGiaiThuong.Visible = true;
                utpTip.Visible = false;
            }
        }

        private void txbHinhThucKhenThuong_Validating(object sender, CancelEventArgs e)
        {
            bool isHasError = false;

            if (txbHinhThucKhenThuong.Text.Trim() == "")
                isHasError = true;

            if (isHasError)
            {
                isHinhThuongKhenThuong = false;
                
                // change NoiSinh's background color to Tomato
                // Add UserTip
                txbHinhThucKhenThuong.BackColor = Color.Tomato;
                utpTip.Value = Language._("KHENTHUONG_FORM_TIP_HINHTHUCKHENTHUONG_NULL");
                utpTip.Visible = true;
                pictureBoxCoQuanQUyetDinh.Visible = false;
            }
            else
            {
                isHinhThuongKhenThuong = true;
                txbHinhThucKhenThuong.BackColor = Color.White;
                pictureBoxCoQuanQUyetDinh.Visible = true;
                utpTip.Visible = false;
            }
        }

        private void txbCoQuanQuyetDinh_Validating(object sender, CancelEventArgs e)
        {
            bool isHasError = false;

            if (txbCoQuanQuyetDinh.Text.Trim() == "")
                isHasError = true;

            if (isHasError)
            {
                isCoQuanQuyetDinhOK = false;
                
                // change NoiSinh's background color to Tomato
                // Add UserTip
                txbCoQuanQuyetDinh.BackColor = Color.Tomato;
                utpTip.Value = Language._("KHENTHUONG_FORM_TIP_COQUANQUYETDINH_NULL");
                utpTip.Visible = true;
                pictureBoxCoQuanQUyetDinh.Visible = false;
            }
            else
            {
                isCoQuanQuyetDinhOK = true;
                txbCoQuanQuyetDinh.BackColor = Color.White;
                pictureBoxCoQuanQUyetDinh.Visible = true;
                utpTip.Visible = false;
            }
        }

        private void txbNoiCap_Validating(object sender, CancelEventArgs e)
        {
            bool isHasError = false;

            if (txbNoiCap.Text.Trim() == "")
                isHasError = true;

            if (isHasError)
            {
                isNoiCapOK = false;
                
                // change NoiSinh's background color to Tomato
                // Add UserTip
                txbNoiCap.BackColor = Color.Tomato;
                utpTip.Value = Language._("HOCHAM_FORM_TIP_COQUANCAP_NULL");
                utpTip.Visible = true;
                pictureBoxNoiCap.Visible = false;
            }
            else
            {
                isNoiCapOK = true;
                txbNoiCap.BackColor = Color.White;
                pictureBoxNoiCap.Visible = true;
                utpTip.Visible = false;
            }
        }

        public bool isKhenThuongOK()
        {
            //Validate
            txbTenGiaiThuong_Validating(txbTenGiaiThuong, null);
            txbHinhThucKhenThuong_Validating(txbHinhThucKhenThuong, null);
            txbCoQuanQuyetDinh_Validating(txbCoQuanQuyetDinh, null);
            txbNoiCap_Validating(txbNoiCap,null);

            isEveryThingOK = isTenGiaiThuongOK && isHinhThuongKhenThuong && isNoiCapOK && isCoQuanQuyetDinhOK;
            return isEveryThingOK;
        }

        public KhenThuong GetKhenThuong()
        {
            if (this.isKhenThuongOK())
            {
                khenThuong = new KhenThuong(txbTenGiaiThuong.Text, txbHinhThucKhenThuong.Text, txbCoQuanQuyetDinh.Text, dtpNgayCap.Value, txbNoiCap.Text);

            }
            return khenThuong;
        }

    }
}
